package com.zhengyao;

import com.zhengyao.service.GreetingService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;

import java.util.Random;


@Service
public class GreetingServiceImpl implements GreetingService {
    Random random = new Random();
    @Override
    public String sayHello(String name) {

        try {
            Thread.sleep(random.nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "Hello GreetingService" + name + " " + RpcContext.getContext().getAttachment("ip");
    }

    @Override
    public String sayWorld(String word) {
        try {
            Thread.sleep(random.nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "Hello GreetingService" + word + " " + RpcContext.getContext().getAttachment("ip");
    }

    @Override
    public String sayBye(String bye) {
        try {
            Thread.sleep(random.nextInt(100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "Hello GreetingService" + bye + " " + RpcContext.getContext().getAttachment("ip");
    }
}
